/* 
 *	Copyright (C) 2009-2010 miaohua
 *	http://code.google.com/p/lrcshower/
 *
 *  This Program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  This Program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with GNU Make; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
 *  http://www.gnu.org/copyleft/gpl.html
 *
 */
#pragma once
#include <vector>
#include <memory>
#include "PlayList.h"
#include "FilterWinSetting.h"
#include "FilterDeskSetting.h"
#include "LrcSearchSetting.h"
#include "LrcShowFilterWrapper.h"

// Show mode
enum ShowMode{WinMode, DeskMode}; 

// Forward declaration
struct IBaseFilter;
class CWinLrcShowDlg;
class CDeskLrcShowDlg;
class CPlayListDlg;

// All setting, property, parameter is in this class
// It includes serialize to from register, and some other operation on its setting
struct MusicBoxSetting
{
     MusicBoxSetting();
     ~MusicBoxSetting();
     // Serialize to and deserialize from window's reg
     bool SerializeToReg();
     bool DeserializeFromReg();
     bool SerializePLToReg(HKEY PlayerKey);
     bool DeserializePLFromReg(HKEY PlayerKey);
     // Serialize to and deserialize from xml file(not be implemented)
     bool SerializeToXML();
     bool DeserializeFromXML();
     // Set defualt value for data member
     void SetDefaultVal();

     // Do lrc search (local or online)
     bool DoLrcSearch(unsigned int SongIdx, unsigned int PLIdx=-1);
     bool DoLrcSearch(const SongProp & Song);
     bool DoLocalLrcSearch(const tstring & SongFullPath, tstring & LrcFullPath);
     bool DoOnlineLrcSearch(const tstring & Song, const tstring & Singer);

     // Operations on play list
     // Just insert appointed song into current play list & show it in play list dialog gui
     // DO NOT change current playing song 
     // It returns the index where the appointed song located in current play list
     // If Pos = -1, add song to ending of playlist
     int AddOneSong(const tstring & SongFullPath, int PLIdx=-1, int Pos=-1);
     int AddOneSongHelper(const tstring & SongFullPath, int PLIdx, int Pos);
     // Move one song from SrcIdx position to DstIdx position 
     int MoveOneSong(int SrcIdx, int DstIdx, int PLIdx);
     // According to given index in current play list,
     // it adjusts m_SelSongIdx to be the input parameter *Index*
     // and search lrc, start lrc show filter
     bool OpenOneSong(unsigned int SongIdx, unsigned int PLIdx=-1);
     // Delete one song according to index
     bool DelOneSong(unsigned int SongIdx, unsigned int PLIdx);
     // Delete all songs in assigned play list
     bool DelAllSong(unsigned int PLIdx);
     // Delete one play list according to index
     bool DelOnePL(unsigned int PLIdx);
     // Add a new play list
     int  AddOnePL(const tstring & PLName);
     // Get next playing song's index in current play list
     // Return -1 means nothing need to play
     // PLIdx = -1 : means current play list
     int GetNextSongIdx(unsigned int PLIdx=-1);
     // Get privious playing song's index in current play list
     // Return -1 means nothing need to play
     // PLIdx = -1 : means current play list
     int GetPrevSongIdx(unsigned int PLIdx=-1);

     // Operations on lrc show filter
     bool LoadAssignedLrc(const tstring & LrcFullPath);
     void ReloadWinLrc();
     void ReloadDeskLrc();
     bool StartLrcShow();

     // Operations on windows
     // Update window lrc area after background color changed
     void InvalidateLrcWin();
     // Show lrc dialog in the right position
     void ShowLrcDlg(HWND ParentHwnd);
     // Show pl dialog in the right position
     void ShowPLDlg(HWND ParentHwnd);
     // Change lrc show mode from window to desktop, and visa vise
     void ChangeShowMode();
     // Notify play list dialog that current playing song's index
     void NotifyPLDlg(int SongIdx);

     // Operations on get song properties
     // Get song's property functions
     // Get current song's duration
     REFERENCE_TIME GetSongDura(int SongIdx=-1, int PLIdx=-1)const;
     REFERENCE_TIME GetDuraHelper(int SongIdx, int PLIdx)const;
     // Get song's next property
     tstring GetSongNextProp(int SongIdx=-1, int PLIdx=-1);
     tstring GetNextPropHelper(int SongIdx, int PLIdx);
     // Get song's label(-1 means get current song's label)
     tstring GetSongLabel(int SongIdx=-1, int PLIdx=-1)const;
     tstring GetLabelHelper(int SongIdx, int PLIdx)const;
     // Get song's full path(-1 means get current song's full path)
     tstring GetSongFullPath(int SongIdx=-1, int PLIdx=-1)const;
     tstring GetFullPathHelper(int SongIdx, int PLIdx)const;
     // Get song's name(-1 means get current song's name
     tstring GetSongName(int SongIdx=-1, int PLIdx=-1)const;
     tstring GetNameHelper(int SongIdx, int PLIdx)const;
     // Get singer's name(-1 means get current song's name
     tstring GetSingerName(int SongIdx=-1, int PLIdx=-1)const;
     tstring GetSingerHelper(int SongIdx, int PLIdx)const;
     // Get song's properties for whole play list
     // Use multi thread(-1 means get current play list)
     bool GetPLSongProp(unsigned int PLIdx=-1);
     // Get song's tips
     // Use multi thread(-1 means get current play list)
     tstring GetSongTips(unsigned int SongIdx=-1, unsigned int PLIdx=-1);
     // Wether it is current playing song
     bool IsCurPlayingSong(unsigned int SongIdx, unsigned int PLIdx);

     // Properties operation
     // Operation on volume
     static long GetSilenceVol();
     long GetVolume();
     void SetVolume(long Vol);
     bool IsMute();
     void SetMute(bool Mute);
     int GetPlayMode()const;
     void SetPlayMode(int Mode);
     ShowMode GetShowMode()const;
     int GetSelPLIdx()const;
     tstring GetCurSongFullPath()const;
     tstring GetCurLrcFullPath()const;
     bool GetRecurse()const;
     void SetRecurse(bool IsRecurse);
     

     int m_PlayMode;                                 // Play mode: Loop, rand, list(play a playlist not single song)
     ShowMode m_ShowMode;                            // Show mode: WinMode or DeskMode
     CLrcShowFilterWrapper m_LrcShowFilter;          // Lrc show filter com interface
     PlayList m_PlayList;                            // Play list
     int m_SelPlayListIdx;                           // Current selected play list' index in list
     tstring m_SongFullPath;                         // Current playing song's full path
     tstring m_LrcFullPath;                          // Current playing song's lrc full path
     bool m_Mute;                                    // Wether to be mute
     long m_Volume;                                  // Value of volume
     static long VOLUME_FULL;                        // Value is 0L(full)
     static long VOLUME_SILENCE;                     // Value is -5000L(silence)
     bool m_IsRecurse;                               // Wether includes sub folder when add folder in play list dialog

     RECT m_LrcShowWinRect;                          // Rectangle for lrc show window
     RECT m_LrcShowDeskRect;                         // Rectangle for lcc show desktop
     RECT m_PLDlgRect;                               // Play list dialog's position and size
     RECT m_LrcWinDefaultRect;                       // Default rectangle for window lrc show
     RECT m_LrcDeskDefaultRect;                      // Default rectangle for desktop lrc show
     std::auto_ptr<CWinLrcShowDlg> m_WinLrcShowDlg;  // Handler of window lrc show dialog
     std::auto_ptr<CDeskLrcShowDlg> m_DeskLrcShowDlg;// Handler of lrc desktop lrc show dialog
     std::auto_ptr<CPlayListDlg> m_PLDlg;            // Handler of play list dialog

     FilterWinSetting m_WinProp;
     FilterDeskSetting m_DeskProp;
     LrcSearchSetting m_LrcProp;  
};